﻿
namespace TwoPageView3 {
    public class FolderTreeViewItemViewModel : FileSystemTreeViewItemViewModel {
        private TpvDirectoryInfo mDirectoryInfo;

        public TpvDirectoryInfo DirectoryInfo {
            get { return mDirectoryInfo; }
        }

        public FolderTreeViewItemViewModel(string actualName, string displayName, FolderTreeViewItemViewModel parent) 
                : base(actualName, displayName, parent) {
            mDirectoryInfo = TpvDirectoryInfo.Factory(MakePath());
            InitChildren(mDirectoryInfo == null || mDirectoryInfo.HasSubDirectory());
        }

        protected override void LoadChildren() {
            var subdir = mDirectoryInfo.EnumerateDirectories();
            foreach (var dir in subdir) {
                if (dir.IsPdf()) {
                    Children.Add(new PdfTreeViewItemViewModel(dir.Name, dir.Name, this));
                } else {
                    Children.Add(new FolderTreeViewItemViewModel(dir.Name, dir.Name, this));
                }
            }
        }
    }
}
